n = input()
if len(n) != 4 or not n.isdigit():
    print(0)
else:
    n = int(n)
    for i in range(4, 0, -1):
        for j in range(0, 4 - i + 1):
            cr = int(str(n)[j:j + i])
            q = True
            for k in range(2, int(cr ** 0.5) + 1):
                if cr % k == 0:
                    q = False
                    break
            if q and cr > 1:
                print(cr)
                exit()
    print(0)
